import gc

import time
import __init__
import simplejson
import demjson

import json

gc.disable()

_str = '''
{"a":1,"b":"2","c":3.0,"d":[1,2,3],"e":{"a":1},"f":true,"g":false,"h":-4e-1}
'''

type_json_res = __init__.loads(_str)

json_res = json.loads(_str)

simple = simplejson.loads(_str)

dem = demjson.decode(_str)

print (type_json_res == json_res)
print (json_res == simple)
print (json_res == dem)

TIMES = 1000

start = time.clock()
for i in range(0, TIMES):
    __init__.loads(_str)
end = time.clock()
t1 = end - start
print ('TypeJson costs: ' + str(t1) + ' seconds: ' + str(int(TIMES / t1)) + ' per sec')

start = time.clock()
for j in range(0, TIMES):
    simplejson.loads(_str)
end = time.clock()
t2 = end - start
print ('SimpleJson costs: ' + str(t2) + ' seconds: ' + str(int(TIMES / t2)) + ' per sec')

start = time.clock()
for k in range(0, TIMES):
    json.loads(_str)
end = time.clock()
t3 = end - start
print ('Python json (c extension) costs: ' + str(t3) + ' seconds: ' + str(int(TIMES / t3)) + ' per sec')

start = time.clock()
for l in range(0, TIMES):
    demjson.decode(_str)
end = time.clock()
t4 = end - start
print ('DemJson costs: ' + str(t4) + ' seconds: ' + str(int(TIMES / t4)) + ' per sec')

print (t1 / t2)
print (t1 / t3)
print (t1 / t4)
